use std::collections::{HashSet, HashMap};
use super::reg::RegType;
use super::liveness::Interval;
use crate::riscv::*;

struct InterferGraph {
    pub vertexes: HashSet<String>,
    pub edges: HashMap<String, HashSet<String>>,
}

#[allow(unused)]
impl InterferGraph {
    pub fn new() -> Self {
        InterferGraph {
            vertexes: HashSet::new(),
            edges: HashMap::new(),
        }
    }

    pub fn build_graph(&mut self, intervals: Vec<(&str, Interval)>, spilled: &HashSet<String>, reg_types: &HashMap<String, RegType>) {
        for (virt, live) in intervals.iter().filter(|(v, _)| !spilled.contains(*v)) {
            let ty = reg_types.get(*virt).unwrap();
            self.vertexes.insert(String::from(*virt));
            let interfers = intervals.iter()
                .filter(|(v, l)| ty == reg_types.get(*v).unwrap() && live.is_interfer(l))
                .map(|(v, _)| String::from(*v))
                .collect::<HashSet<_>>();
            self.edges.insert(String::from(*virt), interfers);
        }
    }

    pub fn coloring(&mut self, colors: HashMap<RegType, Vec<&'static str>>, spilled: &mut HashSet<String>) -> Option<HashMap<String, &'static str>> {
        None
    }
}

#[allow(dead_code)]
struct Coloring<'func> {
    pub target: Option<&'func AsmFunc>,
    pub intervals: Vec<(&'func str, Interval)>,
    pub spilled: HashSet<String>,
}

